# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmariadbclient

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.0
pkgrel=1
pkgdesc="MariaDB client libraries (mingw-w64)"
arch=('any')
url="http://mariadb.org"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-openssl" "${MINGW_PACKAGE_PREFIX}-zlib") #"${MINGW_PACKAGE_PREFIX}-sqlite3"
options=('!strip' 'staticlibs')
source=("ftp://ftp.osuosl.org/pub/mariadb/client-native-${pkgver}/src/mariadb_client-${pkgver}-src.tar.gz"
    fix-libnames-mingw.patch)
sha256sums=('fd2f751dea049c1907735eb236aeace1d811d6a8218118b00bbaa9b84dc5cd60'
            '5a713fff49bdb7aadebda130d5ea4416a05fb9ebe4b0abe19ef6ecc1b05e2ab6')

prepare() {
  cd ${srcdir}/mariadb_client-${pkgver}-src
  patch -p1 -i ${srcdir}/fix-libnames-mingw.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null
  
  mkdir -p ${srcdir}/${MINGW_CHOST}
  cd ${srcdir}/${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DWITH_EXTERNAL_ZLIB=ON \
    -DWITH_SQLITE=OFF \
    -DWITH_OPENSSL=ON \
    ../mariadb_client-${pkgver}-src
  make
}

package() {
  cd "${srcdir}/${MINGW_CHOST}"
  make install

  cp "${pkgdir}${MINGW_PREFIX}"/lib/{libmariadb,libmysqlclient}.dll.a
  cp "${pkgdir}${MINGW_PREFIX}"/lib/{libmariadb,libmysqlclient_r}.dll.a
  cp "${pkgdir}${MINGW_PREFIX}"/lib/{libmariadbclient,libmysqlclient}.a
  cp "${pkgdir}${MINGW_PREFIX}"/lib/{libmariadbclient,libmysqlclient_r}.a
}
